package com.bzframework.core.utils;

import com.bzframework.core.constant.HeaderConstants;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 获取全局请求对象工具类
 */
public class StaticRequestUtils {

    private StaticRequestUtils() {}

    /**
     * 获取request对象
     * @return HttpServletRequest
     */
    public static HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    /**
     * @return 获取请求头中的token
     */
    public static String getAccessTokenByHeader() {
        return getRequest().getHeader(HeaderConstants.X_ACCESS_TOKEN);
    }

}
